/**
 * @FileName Client.java
 * @Package com.designMode.interpreter
 * -------------------------------------
 * @function Please write description of function
 * @Date 2016-1-19 下午3:10:57
 * -------------------------------------
 * Copyright (c) 2016,顾博君 All Rights Reserved.
 */
package com.designMode.interpreter;

import com.designMode.interpreter.nonterminal.*;
import com.designMode.interpreter.terminal.MyBoolean;
import com.designMode.interpreter.terminal.MyInt;
import com.designMode.interpreter.terminal.Variable;

/**
 * @author 顾博君
 * @ClassName Client
 * @Date 2016-1-19 下午3:10:57
 * @Function 场景类
 */
public class Client {
    public static void main(String[] args) {
        Context ctx = new Context();
        // 变量x
        Variable x = new Variable("x");
        // 变量y
        Variable y = new Variable("y");
        // 变量z
        Variable z = new Variable("z");
        // 变量赋值
        ctx.assign(x, MyBoolean.FALSE);
        ctx.assign(y, MyBoolean.TRUE);
        ctx.assign(z, new MyInt(5));
        System.out.println("x=" + x.interpret(ctx));
        System.out.println("y=" + y.interpret(ctx));
        System.out.println("z=" + z.interpret(ctx));
        // 表达式(true AND x)
        AbstractExpression exp1 = new And(MyBoolean.TRUE, x);
        System.out.println(exp1.toString() + "=" + exp1.interpret(ctx));
        // 表达式((true AND x) OR (y AND (NOT x)))
        AbstractExpression exp2 = new Or(new And(MyBoolean.TRUE, x), new And(y, new Not(x)));
        System.out.println(exp2.toString() + "=" + exp2.interpret(ctx));
        // 表达式((z + 3) + 2)
        AbstractExpression exp3 = new Add(new Add(z, new MyInt(3)), new MyInt(2));
        System.out.println(exp3.toString() + "=" + exp3.interpret(ctx));
        // 表达式(2 + (z * 3))
        AbstractExpression exp4 = new Add(new MyInt(2), new Multiply(z, new MyInt(3)));
        System.out.println(exp4.toString() + "=" + exp4.interpret(ctx));

        System.out.println("表达式1,2是否是同一个表达式：" + exp1.equals(exp2));
    }
}
